package br.com.mtg.movethegarbage.graphics;

public class Animation
{
	long timer;
	boolean loop;
	Sprite[] sprites;
	long duration;

	public Animation(long _duration, Sprite... _sprites)
	{
		sprites = _sprites;
		duration = _duration;
		timer = System.currentTimeMillis();
	}

	public Sprite getKeyFrame()
	{
		int n = Math.round(((System.currentTimeMillis() - timer) / duration));
		if (loop)
			n = n / sprites.length;
		else
			n = (n < sprites.length - 1 ? n : 0);

		return sprites[n];
	}

	public void setLooping(boolean _loop)
	{
		loop = _loop;
		timer = System.currentTimeMillis();
	}
}
